HAL SDRAM migration: List of applicable concepts

This section provides information about the HAL SDRAM applicable architecture concepts.

Concepts for SDRAM

Concept

Description

Separation of initialization and configuration functions

The initialization has been split into separate init and config functions:

  • HAL_SDRAM_Init(): initializes the handle and links it to a SDRAM instance.

  • HAL_SDRAM_SetConfig()/ HAL_SDRAM_SetMemoryConfig(): configure the SDRAM according to the user parameters.

Removal and conversion of init structure to configuration structure

The init structure SDRAM_InitTypeDef has been removed and converted into:

  • hal_sdram_common_config_t: for common configuration.

  • hal_sdram_memory_config_t: for memory configuration.

Renaming of the handle structure

The handle structure SDRAM_HandleTypeDef has been renamed to hal_SDRAM_handle_t.

Renaming unitary init structures

The init structure SDRAM_InitTypeDef is no longer available.It has been replaced by hal_sdram_common_config_t and hal_sdram_memory_config_t.

Remove MspInit and MspDeInit callbacks

The hal_sdram_MspInit() and hal_sdram_MspDeInit() are no longer available, they have been replaced by a user sequence to initializes and configures the SDRAM.

Introduction of HAL user data set/get APIs

Two functions to set and get user data are available: HAL_SDRAM_SetUserData() and HAL_SDRAM_GetUserData().

Individual callback registration APIs replace global register and unregister functions

The callback registration is handled by specific functions for each SDRAM event. These functions are used to register callback functions for different SDRAM events.

Revised and optimized HAL state machine

The SDRAM state machine is reworked to ensure transitions of the peripheral functional states.

Revised and optimized HAL API status returns

The SDRAM functions were updated to return:

  • HAL_INVALID_PARAM: in case of a NULL p_config structure pointer.

  • HAL_TIMEOUT: in case of a user timeout.

  • HAL_OK: in case of a successfully completed operation.

Revised and optimized HAL error management

Redesign the HAL error-handling mechanisms to enhance error detection, reporting, and management..

Replaced TypeDef suffix with _t in type names

All TypeDef parts of the HAL SDRAM driver have been removed and replaced by _t.

Replaced nonmodifiable pointers with const keywords

Const keywords have been added to non-modifiable pointers to ensure that either the pointer itself or the data it points to cannot be modified. This enhances code safety and readability, prevents unintended modifications, and renders code more robust and maintainable.

Assertion implementation and usage in HAL1

The ASSERT_DBG_STATE and ASSERT_DBG_PARAM macros are used to check the parameters and state of the HAL SDRAM driver.

Add HAL PPP Services for Drivers with Handle to Retrieve Corresponding Peripheral Clock Frequency.

HAL SDRAM provides new API to retrieve clock frequency HAL_SDRAM_GetClockFreq().

Replace Finite Parameter Defines (Including PPP Instances) with Enum Types at HAL Levels.

Finite parameters (including SDRAM instances) have been converted into enumerated types (enums) at HAL level. This improves code readability, maintainability, and type safety.

Add HAL_PPP Prefix to All HAL Peripheral APIs (Defines, Macros, Types, and Functions).

All HAL SDRAM functions start with HAL_SDRAM. All HAL SDRAM enum and struct start with hal_sdram.

Replace the assert_param macro with ASSERT_DBG_PARAM, controlled by the USE_ASSERT_DBG_PARAM conditional.

Introduce a conditional compilation flag USE_ASSERT_DBG_PARAM to enable or disable debug parameter assertions, allowing for flexible debugging and validation.

Add ASSERT_DBG_STATE macro controlled by USE_ASSERT_DBG_STATE conditional.

Introduce a conditional compilation flag USE_ASSERT_DBG_STATE to enable or disable debug parameter assertions, allowing for flexible debugging and validation.

Other HAL SDRAM changes

Concept

Consideration

Split the configuration structure into Common configuration structure, Memory configuration structure.

The configuration has been split into:

  • hal_sdram_common_config_t contains the common configuration for all devices.

  • hal_sdram_memory_config_t contains the memory fields for a corresponding device.

Provide new APIs to set the configurations

The configurations are set using:

  • HAL_SDRAM_SetConfig() to set the common configuration,

  • HAL_SDRAM_SetMemoryConfig() to set the device configuration.

  • HAL_SDRAM_CompleteInitSequence() to complete the initialization sequence.

Remove WriteOperation from SDRAM configuration structure.

By default, the write protection is enabled, no initial configuration.

Remove process APIs as they depends of user application.

There is no specific FMC hardware configuration needed, as read and write operations are directly accessible by the user.

Change timing parameters unit from cycle to ms.

The static API is added to convert these values before setting them in the FMC register.

Change the resources accessed from Core to HAL.

The only interface with user is hal_sdram.h, no more core header file ll_fmc.h.

Revise the send command APIs.

The send command APIs and services are redesigned to use command-specific structures containing only the command and its required parameter.

Use the SDRAM device as explicit input parameter in the dedicated APIs instead of configuring it inside the configuration structure.

In HAL2, the user selects the SDRAM device directly as a target parameter in the dedicated APIs (e.g. configuration, send command), rather than specifying it as a filed within the configuration structure.